//
//  HighQualityStoreViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/9.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "HighQualityStoreViewController.h"
#import "HightQualityStoreModel.h"
#import "HighQualityStoreViewModel.h"
#import "StoreInformationViewController.h"

@interface HighQualityStoreViewController ()<HighQualityStoreDelegate>{
    HightQualityStoreModel * storeModel;
}
@property (nonatomic,strong) HighQualityStoreViewModel * storeViewModel;
@end

@implementation HighQualityStoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"优质店铺";
    self.storeViewModel = [[HighQualityStoreViewModel alloc] initWithViewToViewModel:self.tableView theSuperView:self.view];
    self.storeViewModel.delegate = self;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#F2F2F2"];
    [self headerRereshing];
}

-(void)headerRereshing{
    self.page = 1;
    [self loadData];
}

-(void)footerRereshing{
    if (self.page < storeModel.data.pages) {
        self.page ++;
        [self loadData];
    }else{
        [GLGWProgressHUD showNotice:@"没有更多店铺信息了！" view:nil];
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }
}

-(void)loadData
{
    @weakify(self)
    [[self.storeViewModel.store_recommendCommand execute:[NSNumber numberWithInteger:self.page]]subscribeNext:^(id x) {
        @strongify(self)
        self->storeModel = (HightQualityStoreModel *)x;
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }error:^(NSError *error) {
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
        
    }];
}

#pragma mark -- HighQualityStoreDelegate
-(void)stroreInformation:(HightQualityStoreModel_Infos *)infos_model{
    StoreInformationViewController * s_informationVc = [StoreInformationViewController new];
    s_informationVc.qua_Model = infos_model;
    [self.navigationController pushViewController:s_informationVc animated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

@end
